return self.getDeviceController(dev_type).sxpr(devid)
- def device_configure(self, dev_config, devid):
+ def device_configure(self, dev_config):
"""Configure an existing device.
@param dev_config: device configuration
- @param devid: device id
"""
deviceClass = sxp.name(dev_config)
- self.reconfigureDevice(deviceClass, devid, dev_config)
+ self.reconfigureDevice(deviceClass, None, dev_config)
def pause(self):
"""
devid = int(devid)
-
- frontpath = self.frontendPath(devid)
- backpath = xstransact.Read(frontpath, "backend")
- if backpath:
- xstransact.Write(backpath, 'state', str(xenbusState['Closing']))
- else:
- raise VmError("Device %s not connected" % devid)
-
+ self.writeBackend(devid, 'state', str(xenbusState['Closing']))
+
def configurations(self):
return map(self.configuration, self.deviceIDs())
return map(int, xstransact.List(fe))
+ def writeBackend(self, devid, *args):
+ frontpath = self.frontendPath(devid)
+ backpath = xstransact.Read(frontpath, "backend")
+
+ if backpath:
+ xstransact.Write(backpath, *args)
+ else:
+ raise VmError("Device %s not connected" % devid)
+
+
## private:
def addStoreEntries(self, config, devid, backDetails, frontDetails):
from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
from xen.xend.XendError import *
+from xen.xend.XendLogging import log
from types import ListType
def lookup(domid):
finally:
f.close()
-methods = ['device_create', 'destroyDevice', 'getDeviceSxprs',
+methods = ['device_create', 'device_configure', 'destroyDevice',
+ 'getDeviceSxprs',
'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
'send_sysrq', 'getVCPUInfo', 'waitForDevices']
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
-# Copyright (C) 2005 XenSource Ltd
+# Copyright (C) 2005, 2006 XenSource Inc.
#============================================================================
return (devid, back, front)
+ def reconfigureDevice(self, _, config):
+ """@see DevController.reconfigureDevice"""
+ (devid, new_back, new_front) = self.getDeviceDetails(config)
+
+ (dev, mode) = self.readBackend(devid, 'dev', 'mode')
+ dev_type = self.readFrontend(devid, 'device-type')
+
+ if (dev_type == 'cdrom' and new_front['device-type'] == 'cdrom' and
+ dev == new_back['dev'] and mode == 'r'):
+ self.writeBackend(devid,
+ 'type', new_back['type'],
+ 'params', new_back['params'])
+ else:
+ raise VmError('Refusing to reconfigure device %s:%d to %s' %
+ (self.deviceClass, devid, config))
+
+
def configuration(self, devid):
"""@see DevController.configuration"""
or the device name as mounted in the guest"""
block_list_help = "block-list <DomId> [--long] List virtual block devices for a domain"
+block_configure_help = """block-configure <DomId> <BackDev> <FrontDev> <Mode>
+ [BackDomId] Change block device configuration"""
network_attach_help = """network-attach <DomID> [script=<script>] [ip=<ip>] [mac=<mac>]
[bridge=<bridge>] [backend=<backDomID>]
Create a new virtual network device """
"block-attach",
"block-detach",
"block-list",
+ "block-configure",
"network-attach",
"network-detach",
"network-list",
"%(be-path)-30s "
% ni)
-def xm_block_attach(args):
- arg_check(args, 'block-attach', 4, 5)
+def parse_block_configuration(args):
dom = args[0]
if args[1].startswith('tap:'):
traceback.print_exc(limit=1)
sys.exit(1)
+ return (dom, vbd)
+
+
+def xm_block_attach(args):
+ arg_check(args, 'block-attach', 4, 5)
+
+ (dom, vbd) = parse_block_configuration(args)
server.xend.domain.device_create(dom, vbd)
+def xm_block_configure(args):
+ arg_check(args, 'block-configure', 4, 5)
+
+ (dom, vbd) = parse_block_configuration(args)
+ server.xend.domain.device_configure(dom, vbd)
+
+
def xm_network_attach(args):
arg_check(args, 'network-attach', 1, 10000)
"block-attach": xm_block_attach,
"block-detach": xm_block_detach,
"block-list": xm_block_list,
+ "block-configure": xm_block_configure,
# network
"network-attach": xm_network_attach,
"network-detach": xm_network_detach,